﻿using AutoMapper;
using HealthcareSystem.API.Write.Application.Command.Disease;
using HealthcareSystem.Domain.BasicSettings.Diseasemanagement;
using HealthcareSystem.Domain.BasicSettings.Element_classification;
using MediatR;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Write.Application.CommandHandel.Disease
{
    /// <summary>
    /// 病列添加
    /// </summary>
    public class AddDiseaseCommandHandler : IRequestHandler<AddDiseaseCommand, ApiResult<int>>
    {
        IBaseRepository<Diseasemanage> diseasemanageHandel;
        IMapper mapper;

        public AddDiseaseCommandHandler(IBaseRepository<Diseasemanage> diseasemanageHandel, IMapper mapper)
        {
            this.diseasemanageHandel = diseasemanageHandel;
            this.mapper = mapper;
        }
        /// <summary>
        /// 病列添加处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ApiResult<int>> Handle(AddDiseaseCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            result.Code = ResultCode.添加成功;
            result.Message = ResultCode.添加成功.ToString();

            var knowledge = mapper.Map<Diseasemanage>(request);
            await diseasemanageHandel.AddAsync(knowledge);


            return await Task.FromResult(result);
        }
    }
}
